#pragma once

#include "TemplateBinding.h"

#include "TemplateParameterSubstitution.h"
#include "TemplateSignature.h"
#include "TemplateableElement.h"

namespace uml {

void TemplateBinding::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    DirectedRelationship::fromJson(json, errorList);
    boundElement_ = JsonSerializable::create<TemplateableElement>(json.value("boundElement"), errorList);

    JsonSerializable::fromJsonArray(parameterSubstitutions_, "parameterSubstitutions", json, errorList);
    signature_ = JsonSerializable::create<TemplateSignature>(json.value("signature"), errorList);

}

void TemplateBinding::toJson(QJsonObject& json) {
    DirectedRelationship::toJson(json);
    if (boundElement_) {
        QJsonObject boundElement_json;
        boundElement_->toJson(boundElement_json);
        json.insert("boundElement", boundElement_json);
    }
    JsonSerializable::toJsonArray(parameterSubstitutions_, "parameterSubstitutions", json);
    if (signature_) {
        QJsonObject signature_json;
        signature_->toJson(signature_json);
        json.insert("signature", signature_json);
    }
}

/// <summary>
/// boundElement getter
/// The TemplateableElement that is bound by this TemplateBinding.
/// </summary>
shared_ptr<TemplateableElement> TemplateBinding::boundElement() const {
    return boundElement_;
}

/// <summary>
/// boundElement setter
/// The TemplateableElement that is bound by this TemplateBinding.
/// </summary>
void TemplateBinding::setBoundElement(shared_ptr<TemplateableElement> value) {
    boundElement_ = value;
}

/// <summary>
/// parameterSubstitutions getter
/// The TemplateParameterSubstitutions owned by this TemplateBinding.
/// </summary>
vector<shared_ptr<TemplateParameterSubstitution>>& TemplateBinding::parameterSubstitutions() {
    return parameterSubstitutions_;
}

/// <summary>
/// signature getter
/// The TemplateSignature for the template that is the target of this
/// TemplateBinding.
/// </summary>
shared_ptr<TemplateSignature> TemplateBinding::signature() const {
    return signature_;
}

/// <summary>
/// signature setter
/// The TemplateSignature for the template that is the target of this
/// TemplateBinding.
/// </summary>
void TemplateBinding::setSignature(shared_ptr<TemplateSignature> value) {
    signature_ = value;
}

} // namespace uml
